﻿namespace TimeMachine.Engine.Metrics
{
	public class MetricValue
	{
		public MetricValue(int rev, string metricId, double value)
		{
			Rev = rev;
			MetricId = metricId;
			Value = value;
		}

		public int Rev { get; private set; }

		public double Value { get; private set; }

		public string MetricId { get; private set; }

		public override string ToString()
		{
			return string.Format("{1} = {0}", Value, MetricId);
		}

		public bool Equals(MetricValue other)
		{
			if (ReferenceEquals(null, other)) return false;
			if (ReferenceEquals(this, other)) return true;
			return other.Value == Value && Equals(other.MetricId, MetricId);
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj)) return false;
			if (ReferenceEquals(this, obj)) return true;
			if (obj.GetType() != typeof (MetricValue)) return false;
			return Equals((MetricValue) obj);
		}

		public override int GetHashCode()
		{
			unchecked
			{
				return (Value.GetHashCode()*397) ^ (MetricId != null ? MetricId.GetHashCode() : 0);
			}
		}
	}
}